package org.jpropeller.problem.impl;

import org.jpropeller.bean.impl.BeanDefault;
import org.jpropeller.problem.Problem;
import org.jpropeller.properties.Prop;

/**
 * Default immutable implementation of {@link Problem}
 */
public class ProblemDefault extends BeanDefault implements Problem {

	private Prop<String> description;
	private Prop<String> location;
	private Prop<ProblemSeverity> severity;
	
	/**
	 * Create a new {@link ProblemDefault}
	 * 
	 * @param description 	see {@link #description()}
	 * @param location 		see {@link #location()}
	 * @param severity 		see {@link #severity()}
	 */
	public ProblemDefault(String description, String location,
			ProblemSeverity severity) {
		super();
		this.severity = create(ProblemSeverity.class, "severity", severity);
		this.description = create("description", description);
		this.location = create("location", location);
	}
	
	@Override
	public boolean equals(Object o)
	{
		if(o instanceof ProblemDefault)
		{
			ProblemDefault p=(ProblemDefault)o;
			if((p.description.get()==null && description.get()==null) || (p.description.get().equals(description.get())))
			{
			if((p.location.get()==null && location.get()==null) || (p.location.get().equals(location.get())))
			{
			if((p.severity.get()==null && severity.get()==null) || (p.severity.get().equals(severity.get())))
			{
				return true;
			}
			}
			}
		}
		return false;
	}

	@Override
	public Prop<String> description() {return description;}

	@Override
	public Prop<String> location() {return location;}

	@Override
	public Prop<ProblemSeverity> severity() {return severity;}
	
	@Override
	public String toString() {
		return description().get() + " at " + location().get() + ", " + severity().get();
	}

}
